﻿@using Apps.Web.Core;
@using Apps.Web;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "入厂煤化验结果查询";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}
<div class="mvctool">
    <input id="txtBatch" type="text" class="condition-batch" placeholder="批次编码" />
    <input id="txtSample" type="text" class="condition-batch" placeholder="制样编码" />
    <input id="txtLms" type="text" class="condition-batch" placeholder="化验编码" />
    <select class="easyui-combobox" name="TYPE_ID" id="TYPE_ID" style="width:250px;"></select>
    <input id="txtStartDate" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', maxDate: '#F{$dp.$D(\'txtEndDate\')}' })" class="condition-date" type="text" placeholder="入厂日期起" />
    <input id="txtEndDate" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', minDate: '#F{$dp.$D(\'txtStartDate\')}' })" class="condition-date" type="text" placeholder="入厂日期止" />
    @Html.ToolButton("btnQuery", "fa fa-search", Resource.Query, ref perm, "Query", true)
    @*@Html.ToolButton("btnFiles", "fa fa-list", "岩相附件", ref perm, "YANXFILES", true)*@
</div>
<table border="0" style="width:100%">
    <tr><td><table id="List"></table></td></tr>
    <tr><td>化检结果详情</td></tr>
    <tr><td><table id="ListDetail"></table></td></tr>
</table>
<div id="modalwindow" class="easyui-window" style="width:800px; height:400px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
<script type="text/javascript">
    $(function () {

        $.ajax({
            url: '../../RC/SAMPLING/GetTranSuppList?type=4',
            type: 'post',
            dataType: 'json',
            success: function (result) {
                $('#TYPE_ID').combobox({
                    data: result,
                    valueField: 'Value',
                    textField: 'Text',
                    onLoadSuccess: function () {

                    }
                });
            },
        });

        $('#ListDetail').datagrid({
            url: '@Url.Action("GetListDetail")',
            width: SetGridWidthSub(10),
            methord: 'post',
            height: SetGridHeightSub(360),
            fitColumns: true,
            sortName: 'INDEX_ID',
            sortOrder: 'asc',
            idField: 'INDEX_ID',
            pageSize: 30,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            rownumbers: true,//行号
            columns: [[
                { field: 'INDEX_NAME', title: '指标名称', width: 80, sortable: true },
                { field: 'INDEX_DISNAME', title: '指标编码', width: 80, sortable: true },
                { field: 'TEST_VALUE', title: '化验结果', width: 80, sortable: true },
                {
                    field: 'TEST_MODE', title: '数据来源', width: 80, sortable: true, formatter: function (value, row) {
                        switch (value) {
                            case 0:
                                return "自动录入";
                            case 1:
                                return "手工录入";
                            case 2:
                                return "第三方化验";
                            case 3:
                                return "系统计算";
                            default:
                                return value;
                        }
                    }
                },
                { field: 'USERNAME', title: '化验员', width: 80, sortable: true },
                { field: 'CONFIRMED_TIME', title: '初级审核', width: 80, sortable: true },
            ]]
        });
        $('#List').datagrid({
            url: '@Url.Action("GetList")',
            width:SetGridWidthSub(10),
            methord: 'post',
            height: 300,
            fitColumns: true,
            sortName: 'BATCH_CODE',
            sortOrder: 'desc',
            idField: 'BATCH_CODE',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            rownumbers: true,//行号
            onClickRow: clickRow,
            onLoadSuccess: function (data) {
                var allRows = $('#List').datagrid('getRows');
                if (allRows.length > 0) {
                    $('#List').datagrid('selectRow', 0);
                    clickRow(0, allRows[0]);
                }
            },
            columns: [[
                { field: 'MATCH_TIME', title: '入厂日期', width: 80, sortable: true , formatter: DateTimeFormatterToDate },
                { field: 'BATCH_CODE', title: '批次编码', width: 80, sortable: true },
                { field: 'MAKE_CODE', title: '制样编码', width: 80, sortable: true },
                { field: 'TEST_CODE', title: '化验编码', width: 80, sortable: true },
                { field: 'MATERIEL_NAME', title: '物料名称', width: 80, sortable: true },
                { field: 'MATERIEL_TYPE_NAME', title: '类型', width: 100, sortable: true },
                /*{ field: 'MINE_NAME', title: '矿点名称', width: 80, sortable: true },*/
                { field: 'SUPPLIER_NAME', title: '供应商名称', width: 80, sortable: true },
                { field: 'TRANSPORT_NAME', title: '运输商名称', width: 80, sortable: true },
                @*{
                    field: 'MAKE_TYPE', title: '是否第三方化验', width: 80, sortable: true, formatter: function (val) {
                        if (val == 1) {
                            return "<img src='@Url.Content("~/image/tick.png")' />"
                        } else {
                            return "<img src='@Url.Content("~/image/bullet_cross.png")' />"
                        }
                    }
                },*@
                {
                    field: 'APPROVAL_STATUS', title: '审批状态', width: 80, sortable: true, formatter: function (value, row) {
                        var statusname = "";
                        switch (row.APPROVAL_STATUS) {
                            case 4:
                                statusname = "申请";
                                break;
                            case 2:
                                statusname = "审批中";
                                if (row.AUDIT_USER_ID == "@(ViewBag.UserID)") {
                                    statusname = "待审批";
                                }
                                break;
                            case 3:
                                statusname = "审批完成";
                                break;
                            case 4:
                                statusname = "已作废";
                                break;
                            default:
                                statusname = "";
                                break;
                        }
                        return statusname;
                    }
                },
            ]]
        });
    });
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
            $("#List").datagrid('load');
        else
            $("#List").datagrid('reload');
    }
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }
    $(function () {
        $("#btnQuery").click(function () {
            var queryStr = $("#txtQuery").val();
            if (queryStr == null) {
                queryStr = "%";
            }
            $("#List").datagrid("load", {
                batch: $("#txtBatch").val(),
                sample: $("#txtSample").val(),
                lms: $("#txtLms").val(),
                startdate: $("#txtStartDate").val(),
                enddate: $("#txtEndDate").val(),
                TYPE_STR: $("#TYPE_ID").combobox('getValues').toString(),
            });
        });

        $("#btnFiles").click(function () {
            
                if (currow != null) {
                    $("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='@Url.Action("Yanx")?id=" + currow.BATCH_CODE + "&Ieguid=" + GetGuid() + "'></iframe>");
                     $("#modalwindow").window({ title: '岩相分析附件', width:500, height: 300, iconCls: 'fa fa-pencil' }).window('open');
                } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
            
         });

    });

    function clickRow(idx, row) {
        if (row != null) {
            $('#ListDetail').datagrid("load", {
                testCode: row.TEST_CODE,
                code: row.BATCH_CODE
            });
            currow = row;
            console.log(currow,'currow');
        }
    }
</script>
